/*
 * copyright (c) 2009 Alexandr [Sn@ble] Surnin
 *
 * This file is part of CVP.
 *
 * CVP is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * CVP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You can read the full version of GNU LGPL in
 * http://www.gnu.org/copyleft/lesser.html
 */


#include "trackheader.h"


TrackHeader::TrackHeader(QWidget *parent)  : QWidget(parent) {

    setFixedSize(280, parent->height());

    trackName = "Track Header";

    createActions();
}


void TrackHeader::paintEvent (QPaintEvent *event) {

    QPainter painter(this);
    QBrush brush(QColor(128, 128, 255));
    painter.setBrush(brush);
    QPen pen(QColor(0, 0, 0));
    pen.setWidth(5);
    painter.setPen(pen);
    painter.drawRect(QRect(0, 0, this->width()-1, this->height()-1));
    painter.drawText(15, 15, trackName);
    painter.drawText(15,35, QString("Widht: %1\nHeight: %2").arg(width()).arg(height()));
    painter.end();
}


void TrackHeader::contextMenuEvent(QContextMenuEvent *event) {

    QMenu menu(this);
    menu.addAction(newAction);
    menu.addAction(renameAction);
    menu.addAction(closeAction);
    menu.exec(event->globalPos());
    //TODO
}


void TrackHeader::createActions() {

    newAction = new QAction("New", this);

    renameAction = new QAction("Rename", this);
    connect(renameAction, SIGNAL(triggered()),
            this, SLOT(renameTrack()));

    closeAction = new QAction("Close", this);

}


void TrackHeader::renameTrack() {

    trackName = "Renamed :-)";
    repaint();
}
